<template lang="html">
  <div class="icons">
    <swiper :options="swiperOption">
       <swiper-slide v-for="(page, index) of pages" :key="index">
         <div class="icon" v-for="item of page" :key="item.id">
           <div class="icon-img-box">
             <img class="icon-img" :src="item.imgUrl">
           </div>
           <p class="icon-desc">{{item.desc}}</p>
         </div>
       </swiper-slide>
       <div class="swiper-pagination"  slot="pagination"></div>
     </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    iconList: Array
  },
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
      // const pages = []
      // for (var i = 0; i < this.iconList.length; i++) {
      //   const page = Math.floor(i / 8)
      //   if (!pages[page]) {
      //     pages[page] = []
      //   }
      //   pages[page].push(this.iconList[i])
      // }
      // return pages
    }
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        autoplay: false
      }
      // iconList: [{
      //   id: '0001',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
      //   desc: '景点门票'
      // }, {
      //   id: '0002',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/ff/fdf170ee89594b02.png',
      //   desc: '必游榜单'
      // }, {
      //   id: '0003',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/6a/45f595250c73d102.png',
      //   desc: '夏日玩水'
      // }, {
      //   id: '0004',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
      //   desc: '一日游'
      // }, {
      //   id: '0005',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/76/eb88861d78fb9902.png',
      //   desc: '动植物园'
      // }, {
      //   id: '0006',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/6c/9e54a8540fee0102.png',
      //   desc: '故宫'
      // }, {
      //   id: '0007',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/47/c2b659e048b11602.png',
      //   desc: '主题乐园'
      // }, {
      //   id: '0008',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/ed/cf572be30fc32f02.png',
      //   desc: 'Q+精选'
      // }, {
      //   id: '0009',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/e3/67df61427c8e1302.png',
      //   desc: '演出'
      // }]
    }
  }
}
</script>

<style lang="stylus" scoped>
  .icons >>> .swiper-container
    padding-bottom: .55rem
  .icons >>> .swiper-pagination-bullet
    width: 6px
    height: 6px
  .icons
    position: relative
    width: 100%
    height: 0
    box-sizing: border-box
    padding-top: .1rem
    padding-bottom: 3.7rem
    .swiper-pagination
      position: absolute
    .icon
      position: relative
      float: left
      width: 25%
      padding-top: .1rem
      padding-bottom: 1.5rem
      text-align: center
      .icon-img-box
        position: absolute
        display: block
        left: 0
        right: 0
        top: .1rem
        width: 100%
        .icon-img
          width: 1.1rem
          height: 1.1rem
      .icon-desc
        position: absolute
        left: 0
        right: 0
        bottom: .1rem
</style>
